package com.hoas.keystore.factory.aes;

import com.hoas.keystore.po.MerchantKey;
import com.hoas.keystore.util.AESUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AESDecoderFactory {

    private static Logger log = LoggerFactory.getLogger(AESDecoderFactory.class);

    public static AESDecoder getDecoder(MerchantKey key) {

        if (key == null) {
            return null;
        }

        if ("AES".equals(key.getKeyType())) {

            try {

                AESDecoder decoder = new AESDecoder(key.getClientPrivateKey());
                decoder.setVersion(key.getKeyVersion());
                decoder.setEncryptText(key.getEncryptText());
                return decoder;

            } catch (Exception e) {
                log.error("客户端编码解析器创建异常", e);
            }

        }

        return null;

    }

    public static void genKeyPairs(MerchantKey key) {

        if (key == null) {
            return;
        }

        if ("AES".equals(key.getKeyType())) {

            try {

                String privateKey = AESUtil.gen();
                key.setClientPrivateKey( privateKey );
                key.setServerPrivateKey( privateKey );


            } catch (Exception e) {
                log.error("客户端编码解析器创建异常", e);
            }

        }



    }

}
